package com.cc.blog.web.controller;

import com.cc.blog.admin.model.UserDO;
import com.cc.blog.common.annotation.ApiOperationLog;
import com.cc.blog.common.enums.CodeEnum;
import com.cc.blog.common.exception.BusinessException;
import com.cc.blog.common.utils.JsonUtil;
import com.cc.blog.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @Author cc
 * @Date 2023/10/18 13:56
 */
@RestController
@Slf4j
@Api(tags = "测试接口")
public class TestController {

    @PostMapping("/test")
    @ApiOperationLog(description = "测试接口")
    @ApiOperation("test")
    public Result test() {
        throw new BusinessException(CodeEnum.AUTH_USER_OVERTIME);
    }
    @PostMapping("/admin/test")
    @ApiOperationLog(description = "测试权限接口")
    @ApiOperation("测试权限接口")
    public Result adminTest(@RequestBody UserDO user) {
        log.info(JsonUtil.toJsonString(user));
        // 设置三种日期字段值
        user.setCreateTime(LocalDateTime.now());
        user.setUpdateTime(LocalDateTime.now());

        return Result.success(user);
    }
}
